function paging(page){
$("[name=page]").val(page);
$("#searchForm").submit();
}
    $(function(){
    	
    	
    	
    	
        $(".btn-danger").click(function(e){
        if(confirm("确定删除吗?"))
        {
            $.ajax({
                url:'/school/deleteById.json?id='+ e.currentTarget.id,
                type:'POST',
                dataType:"json",
                success:function(date) {
                    if(date.suc)
                    {
                        $(".close").click();
                        alert("删除成功！");
                        window.location.href = "/school/schoolList.htm";
                    }else{
                       alert("删除有误！");
                        window.location.href = "/school/schoolList.htm";
                    }
                }
            });
        }
    });
    
    $('.editSchoolBT').click(function(e){
        e.preventDefault();
      //  $("#edit-receivableTime").val($("#invoice-receivableTime-"+e.currentTarget.id).val());
        $("#schoolName").val($("#schoolName-"+e.currentTarget.id).val());
        $("#zoneSel").val($("#zoneId-" + e.currentTarget.id).val());
        $("#edit-slogan").val($("#slogan-"+e.currentTarget.id).val());
        $("#edit-description").val($("#description-"+e.currentTarget.id).val());
        $("#edit_imgShow").attr("src",$("#logUrl-"+e.currentTarget.id).val());
        $("#zoneSel2").val($("#zoneId-"+e.currentTarget.id).val());
        var zoneId = $("#zoneId-"+e.currentTarget.id).val();
        $.ajax({
            url: '/city/queryCityByZoneId.json',
            type: 'POST',
            dataType: "json",
            data: {zoneId: zoneId},
            success: function (data) {
                var citySelect = "";
                var cityId = $("#cityId-"+e.currentTarget.id).val();
                $(data).each(function (i, obj) {
                	if(obj.id == cityId){
                		citySelect += "<option value=" + obj.id + " selected='selected'>" + obj.name + "</option>";
                	}else{
                		citySelect += "<option value=" + obj.id + ">" + obj.name + "</option>";
                	}
                });
                $("#citySel2").empty().append(citySelect);
            }
        });
        $("#edit-id").val(e.currentTarget.id);
        $('#id-input-file-2').ace_file_input({
            no_file: $("#logUrl-"+e.currentTarget.id).val(),
            btn_choose: 'Choose',
            btn_change: 'Change',
            droppable: false,
            onchange: null,
            thumbnail: false
        });
        $('#editModel').modal('show');
    });
    
    $('#id-input-file-1').ace_file_input({
        no_file: '没有文件 ...',
        btn_choose: 'Choose',
        btn_change: 'Change',
        droppable: false,
        onchange: null,
        thumbnail: false//| true | large
    });
    
    $("#updateSchool").validate( {
        checkStart : true,
        errorElement: 'span',
        errorClass: 'help-inline',
        focusInvalid: false,
        rules : {
            name : {
                required: true
            }
        },
        messages : {
            name : {
                required : "必须填写"
            }
        },
        submitHandler : function(form) {

            $("#updateSchool").ajaxSubmit(function(date,res,me){
                if(date.suc){
                    alert("修改成功了！");
                    $(".close").click();
                    window.location.href = "/school/schoolList.htm";
                }else{
                	alert("修改失败了！"+date.msg);
                }
            });
        },
        highlight: function (e) {
            $(e).closest('.control-group').removeClass('info').addClass('error');
        }
    });
    
    $("#addSchool").validate( {
        checkStart : true,
        errorElement: 'span',
        errorClass: 'help-inline',
        focusInvalid: false,
        rules : {
            name : {
                required: true
            }
        },
        messages : {
            name : {
                required : "必须填写"
            }
        },
        submitHandler : function(form) {
        	var cityId = $("#citySel").val();
        	if(cityId ==null){
        		alert("城市不能为空");
        		return false;
        	} else{
        		$("#addSchool").ajaxSubmit(function(date,res,me){
                    if(date.suc){
                        alert("保存成功了！");
                        window.location.href = "/school/schoolList.htm";
                    }else{
                    	alert("添加失败！"+date.msg);
                    }
                });
        	}
        },
        highlight: function (e) {
            $(e).closest('.control-group').removeClass('info').addClass('error');
        }
    });
    
    $(".btn-inverse").click(function(e){
        $("[name=page]").attr("value","1");
    });
    
    
    $('#zoneSel').change(function () {
        var zoneId = $(this).val();
        $.ajax({
            url: '/city/queryCityByZoneId.json',
            type: 'POST',
            dataType: "json",
            data: {zoneId: zoneId},
            success: function (data) {
                var citySelect = "";
                $(data).each(function (i, obj) {
                    citySelect += "<option value=" + obj.id + ">" + obj.name + "</option>";
                });
                $("#citySel").empty().append(citySelect);
            }
        });
    });
    
    $('#zoneSel2').change(function () {
        var zoneId = $(this).val();
        $.ajax({
            url: '/city/queryCityByZoneId.json',
            type: 'POST',
            dataType: "json",
            data: {zoneId: zoneId},
            success: function (data) {
                var citySelect = "";
                $(data).each(function (i, obj) {
                    citySelect += "<option value=" + obj.id + ">" + obj.name + "</option>";
                });
                $("#citySel2").empty().append(citySelect);
            }
        });
    });
    
    var options = {
            currentPage: $("[name=page]").val(),
            totalPages: $("[name=totalPage]").val(),
            alignment:"left",
            itemTexts: function (type, page, current) {
                switch (type) {
                    case "first":
                        return "首页";
                    case "prev":
                        return "上一页";
                    case "next":
                        return "下一页";
                    case "last":
                        return "末页";
                    case "page":
                        return page;
                }
            },
            pageUrl: function(type,page,current){
                return "javascript:paging('"+page+"');";
            }
        };
    $('#example').bootstrapPaginator(options);
    
    
    
});